<template>
  <el-card>
    <div slot="header" class="clearfix">
      <span>公会活动</span>
    </div>
    <el-form ref="activityForm" :model="activity" label-width="100px">
      <el-form-item label="活动名称">
        <el-input v-model="activity.name" placeholder="请输入活动名称"></el-input>
      </el-form-item>
      <el-form-item label="活动时间">
        <el-date-picker v-model="activity.date" type="date" placeholder="选择日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="描述">
        <el-input type="textarea" v-model="activity.description" placeholder="请输入描述"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="createActivity">创建活动</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="activities" style="width: 100%; margin-top: 20px;">
      <el-table-column prop="id" label="活动ID" width="100"></el-table-column>
      <el-table-column prop="name" label="活动名称"></el-table-column>
      <el-table-column prop="date" label="活动时间"></el-table-column>
      <el-table-column prop="description" label="描述"></el-table-column>
      <el-table-column label="操作" width="150">
        <template #default="scope">
          <el-button @click="editActivity(scope.row)" type="primary" size="small">编辑</el-button>
          <el-button @click="deleteActivity(scope.row.id)" type="danger" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { createGuildActivity, getGuildActivitiesByGuildId, updateGuildActivity, deleteGuildActivity } from '@/utils/requests.js';

const activity = ref({
  id: null,
  name: '',
  date: '',
  description: ''
});

const activities = ref([]);

const loadActivities = async () => {
  const response = await getGuildActivitiesByGuildId(1); // 假设公会ID为1
  activities.value = response.data;
};

onMounted(() => {
  loadActivities();
});

const createActivity = async () => {
  await createGuildActivity(activity.value);
  loadActivities();
};

const editActivity = (act) => {
  // 实现编辑活动逻辑
};

const deleteActivity = async (id) => {
  await deleteGuildActivity(id);
  loadActivities();
};
</script>